home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / bit / src / forms / FORMS / support.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  3KB  |  126 lines

  1. /*
  2.  * support.c
  3.  *
  4.  * This file is part of the basis of the Forms Library.
  5.  *
  6.  * It contains the initialization routine and some routines used at
  7.  * many places.
  8.  *
  9.  * Written by: Mark Overmars
  10.  *
  11.  * Version 2.1 a
  12.  * Date: Oct  6, 1992
  13.  */
  14.  
  15. #include <stdio.h>
  16. #include <malloc.h>
  17. #include <string.h>
  18. #include "gl/gl.h"
  19. #include "forms.h"
  20.  
  21. /****** Graphical Mode ******/
  22.  
  23. int fl_rgbmode = TRUE;        /* Whether in RGBmode */
  24. int fl_doublebuf = TRUE;    /* Whether in double buffered mode */
  25.  
  26. static int initialized = FALSE;    /* Whether mode has been initializes */
  27.  
  28. void fl_init()
  29. /* Initialises the FORMS library. */
  30. {
  31.   if (initialized) return;
  32.   initialized = TRUE;
  33.   /* Set the graphics mode based on the machine type */
  34.   if (getgdesc(GD_BITS_NORM_SNG_RED) == 0) /* no rgbmode possible */
  35.     { fl_doublebuf = FALSE; fl_rgbmode = FALSE;}
  36.   else if (getgdesc(GD_BITS_NORM_DBL_RED) < 4) /* no nice double buffering */
  37.     { fl_doublebuf = FALSE;}
  38.   /* intialize the colormap */
  39.   fl_init_colormap();
  40.   /* initialize the fonts used */
  41.   fl_init_fonts();
  42.   /* initialize the event handling */
  43.   fl_init_events();
  44.   /* initialize the symbols */
  45.   fl_init_symbols();
  46. }
  47.  
  48.  
  49. void fl_set_graphics_mode(int rgbmode, int doublebuf)
  50. /* Sets the graphical mode being used. */
  51. {
  52.   fl_init();
  53.   fl_rgbmode = rgbmode;
  54.   fl_doublebuf = doublebuf;
  55. }
  56.  
  57. /****** Error handling ******/
  58.  
  59. static int showerrors = TRUE;
  60.  
  61. void fl_show_errors(int show)
  62. /* Used to switch error checking on and off */
  63.   { showerrors = show; }
  64.  
  65. void fl_error(char str1[], char str2[])
  66. /* Shows a two line alert box */
  67. {
  68.   int rep;
  69.   char str[128];
  70.   if (! showerrors) return;
  71.   sprintf(str,"FORMS Error in %s\n",str1);
  72.   rep = fl_show_choice(str,"",str2,3,"Continue","Exit","Hide Errors");
  73.   if (rep == 2) exit(-1);
  74.   if (rep == 3) showerrors = FALSE;
  75. }
  76.  
  77. /****** Memory Allocation ******/
  78.  
  79. void *fl_malloc(size_t amount)
  80. /* Replacement for the normal malloc, doing checking */
  81. {
  82.   void *ttt = malloc(amount);
  83.   if (ttt == NULL) fl_error("fl_malloc","Cannot allocate memory.");
  84.   return ttt;
  85. }
  86.  
  87. /****** Setting windows ******/
  88.  
  89. static long userwind = -1;        /* The current user window */
  90. static int usersaved = 0;        /* How often user window is saved */
  91. static long formwind = -1;        /* The current form window */
  92.  
  93. void fl_save_user_window()
  94. /* Saves the window identifier for the user window */
  95. {
  96.   if (usersaved++ == 0) userwind = winget();
  97. }
  98.  
  99. void fl_restore_user_window()
  100. /* Sets back the user window */
  101. {
  102.   if (usersaved <= 0)
  103.     fl_error("fl_restore_user_window","Internal Error: usersaved <= 0");
  104.   else if (usersaved > 1) usersaved--;
  105.   else
  106.   {
  107.     if (userwind != -1 && userwind != 257 && userwind != formwind) {
  108. #if 0
  109.        fprintf(stderr,"userwid=%d formwind=%d\n",userwind, formwind);
  110. #endif
  111.        winset(userwind);
  112.      }
  113.     userwind = -1; formwind = -1;
  114.     usersaved = 0;
  115.   }
  116. }
  117.  
  118. void fl_set_forms_window(FL_FORM *form)
  119. /* Sets the form windom */
  120. {
  121.   if (form == NULL || form->window == formwind) return;
  122.   formwind = form->window;
  123.   winset(formwind);
  124. }
  125.  
  126.